#ifndef OEWALLETSELECTWIDGET_H
#define OEWALLETSELECTWIDGET_H

#include <QWidget>

#include <QMap>

class QVBoxLayout;
class QSignalMapper;
class QMenu;
class OEWalletSelectWidget : public QWidget
{
    Q_OBJECT
public:

    struct stWalletInfo{
        QString absPath;
        QString name;
        QString ekPubKey;
        QString logo;
        QString logo_hover;
        QString logo_pressed;
        stWalletInfo(const QString& _filepath = "",
                     const QString& _walletName = "")
            :absPath(_filepath), name(_walletName) {}
    };

    typedef QList<stWalletInfo> OEWalletList;

Q_SIGNALS:

    /**
    * brief: emit finshed signal
    *        abs path modified
    * param: wallet abs path
    */
    void sigFinshed(const QString& _walletPath = "");

    /**
    * brief: emit backup signal
    * param: source wallet abs path
    * param: dest wallet abs path
    */
    void sigBackup(const QString&, const QString&);

    /**
    * brief: emit delete signal
    *        delete wallet
    * param: wallet name
    * param: wallet abs path
    */
    void sigDelete(const QString&, const QString&);

    /**
    * brief: emit create signal
    *        enter create wallet page
    */
    void sigCreate(void);

    /**
    * brief: use folder restore wallet
    * param: need restore wallet path
    */
    void sigRestoreFromFolder(const QString&);

    /**
    * brief: use cryptolalia restore wallet
    */
    void sigRestoreFromCryptolalia(void);


    /**
    * brief: wallet name modify
    * param: old name
    * param: new name
    */
    void sigWalletNameChange(const QString&, const QString&);

public:
    explicit OEWalletSelectWidget(QWidget *parent = 0);

    /**
    * brief: clear wallet widget
    */
    void clearWallet(void);

    /**
    * brief: load wallet
    * param: wallet folder abs path
    * return: load wallet count
    *         int < 0 load error
    */
    int loadWallet(const QString& _path);

    /**
    * brief: create wallet button
    * param: info must contain (path name)
    */
    int createWallet(const stWalletInfo& _info);

protected:

    /**
     * brief: load wallet info - name
     * param: wallet folder abs path
     * param: wallet struct   - out
     * return: 0 : success, not 0 : failed
    */
    int loadWalletInfo(const QString& _rootpath, stWalletInfo& _wallet);

    /**
    * brief: find wallet folder
    * param: wallet root directory path
    * return: list wallet abs path
    *         find wallet failed return list size = 0
    */
    QStringList findWallet(const QString& _path);
private:

    /**
    * brief: convert unknown path to abs path
    *        if _outpath is relative path
    *        convert _outpath to
    *        _outpath = _rootpath + _outpath;
    */
    bool convertPathToAbs(const QString& _rootPath,
                             QString &_outpath);

    /**
    * brief: create click image (hover and pressed)
    *        if (_logoHover || _logoPressed) is null
    *        create images based on _logo
    */
    bool createPixmap(const QString& _logo,
                      QString& _logoHover,
                      QString& _logoPressed);

    /**
    * brief: check path is wallet folder
    * param: _path is wallet folder path
    * return: true is yes, false is no
    */
    bool isWallet(const QString& _path);


    /**
    * brief: create wallet menu
    * retuen: return menu
    */
    QMenu* createWalletMenu(const stWalletInfo& _info);

protected Q_SLOTS:

    /**
    * brief: enter _absPath
    *        use _absPath become work path
    */
    bool onHandoverWorkPath(const QString& _absPath);



private:
    QSize sizeWallet_;

    OEWalletList listInfo_;

    QMap<QString, QString> mapFileName_;

    QSignalMapper* mapper_;

    QVBoxLayout* layout_;
};

#endif // OEWALLETSELECTWIDGET_H
